##
# MPInteger Tester Makefile
#
# Built from Bill Garrison's Objective-C Project Makefile Template
#
# Written by Bill Garrison
# Last changed 2010 Apr 18
##

### Begin Project Parameters ###

ProjectName = MPInteger-Tester
Sources = tester.m
Folders = MPInteger
OtherPrintables = 
OtherArchivables = 
PrintFile = Source\ Listing
export PrintTemp = Print\ Temp
OtherPurgables = 

### End Project Parameters ###

### Begin Project Dependencies ###

all: bin
MPIHeaders = MPInteger Declare Init Set Convert Arithmetic Get Division \
   Exponent Compare NumberTheory Random Constants
objrsa.o: $(addprefix MPInteger/,$(addsuffix .h,$(MPIHeaders)))

### End Project Dependencies ###

### Begin Configuration Parameters ###

export CC = gcc
export CFlags = -g -arch i386 -O2 -Wimplicit-function-declaration
export Prefix = /opt/local /usr/local
Libraries = objc gmp
Frameworks = 
export RM = rm -f
TAR = tar -hv --exclude=".DS_Store" --exclude=".svn"
export MORE = more
ReleaseFormat = tgz

### End Configuration Parameters ###

### Begin Generic Expansions ###

Objects = $(Sources:.m=.o)
FolderObjects = $(Folders:=/*.o)
AllObjects = $(Objects) $(FolderObjects)
Executable = $(ProjectName).out
Archivables = Makefile $(Sources) $(Folders) $(OtherArchivables)
PrefixExpanded = $(addsuffix /include/,$(addprefix -I,$(Prefix))) \
   $(addsuffix /lib/,$(addprefix -L,$(Prefix)))
CFlagsExpanded = $(CFlags) $(PrefixExpanded)
LibrariesExpanded = $(addprefix -l,$(Libraries))
FrameworksExpanded = $(addprefix -framework ,$(Frameworks))

### End Generic Expansions ###

### Begin Generic Rules ###

bin: $(Executable)

run: $(Executable)
	@echo "" # These are solely for tcsh because it sucks.
	@echo "Running $(Executable)..."
	@echo ""
	@./$(Executable)
	@echo ""
	@echo "$(Executable) quit."

$(Executable): folders $(Objects)
	$(CC) $(LibrariesExpanded) $(FrameworksExpanded) $(CFlagsExpanded) \
   $(AllObjects) -o $@

%.o: %.m %.h
	$(CC) -c $(CFlagsExpanded) $< -o $@

%.o: %.m
	$(CC) -c $(CFlagsExpanded) $< -o $@

folders:
	$(foreach Folder,$(Folders),$(MAKE) -C $(Folder);)

remake: clean bin

straight: bin clean-folders clean-noex

clean: clean-all

clean-all: clean-folders clean-ex

clean-folders:
	$(foreach Folder,$(Folders),$(MAKE) -C $(Folder) clean;)

clean-ex: clean-noex
	$(RM) $(Executable)

clean-noex: clean-archives
	$(RM) core $(Executable).core $(Objects) $(PrintFile).ps $(PrintFile).pdf \
   $(OtherPurgables)

clean-archives:
	$(RM) $(ProjectName).tar $(ProjectName).tgz $(ProjectName).tbz

release: clean $(ReleaseFormat) move-release

move-release:
	mkdir -p Release
	mv $(ProjectName).$(ReleaseFormat) Release/$(ProjectName)-r___.$(ReleaseFormat)

tar: clean-folders
	export COPYFILE_DISABLE=true;\
	$(TAR) -cf $(ProjectName).tar $(Archivables)

tgz: clean-folders
	export COPYFILE_DISABLE=true;\
	$(TAR) -czf $(ProjectName).tgz $(Archivables)

tbz: clean-folders
	export COPYFILE_DISABLE=true;\
	$(TAR) -cjf $(ProjectName).tbz $(Archivables)

print: print-folders
	-$(MORE) Makefile $(Sources) $(OtherPrintables) \
   $(foreach Folder,$(Folders),$(Folder)/$(PrintTemp).txt ) | \
   enscript -p $(PrintFile).ps

print-folders:
	$(foreach Folder,$(Folders),$(MAKE) -C $(Folder) PrintHelper;)

pdf: print
	-pstopdf $(PrintFile).ps -o $(PrintFile).pdf

### End Generic Rules ###

